/**
 * Created with IntelliJ IDEA.
 * User: zhengry
 * Date: 2014/11/6
 * Time: 17:51
 */

// ${appDir}/system/controller/UserController.js
define(['system/user/UserModule', 'framework/tree/GillionTreeModule'], function (UserModule) {
    return UserModule.controller('UserController', function ($scope, ResourceService) {
        /*$scope.resourceMethods = {
         exists: {url: '/system/users/exists/:name'},
         getByName: {url: '/system/users/getByName/:name'}
         };

         $scope.userGridRowClick = function () {
         console.log(arguments)

         };
         */
        /*Users.then(function (Users) {
         Users.exists({id: 1});
         });*/
        /*
         */
        /*$scope.watch('current.name', function (val) {
         $scope.Users.exists({name: val}).then(function (exists) {
         if (exists) {
         // TODO somethings
         }
         });
         });*/
        /*

         $scope.findByName = function (event) {
         var val = event.target.value;
         };
         */
        /*$scope.UserService.getByName({name: val}).then(function (result) {
         $scope.current = result.data;
         })*/
        /*
         $scope.treeOptions = {
         view: {
         showLine: false,
         showIcon: false
         },
         callback: {
         onNodeCreated: function () {
         console.log($('#tree').html())
         }
         }
         };

         $scope.employeeTreeData = [
         {
         "children": [
         {
         "children": [
         {
         "name": "操作",
         "checked": true,
         "id": 3
         },
         {
         "name": "结算",
         "id": 4
         },
         {
         "name": "管理员",
         "id": 5
         }
         ],
         "name": "买家",
         "id": 2,
         "open": true
         },
         {
         "children": [
         {
         "name": "操作",
         "id": 7
         },
         {
         "name": "结算",
         "id": 8
         },
         {
         "name": "管理员",
         "id": 9
         }
         ],
         "name": "卖家",
         "id": 6,
         "open": true
         }
         ],
         "name": "客户角色",
         "id": 1,
         "open": true
         }
         ];
         $scope.resourceInitCallback = function () {
         */
        /*  $scope.Users.query(function (result) {
         $scope.employeeTreeData = result;
         });*/
        /*
         };*/
        $scope.UserGridInitCallback = function (api) {
            Arrays.doForAll(api.source, function (element) {
                element.checked = true;
            });
        };
        $scope.onsubmit = function () {
            $scope.gridApi.toggleAll()
        };
        $scope.UserGridColumns = [
            {
                header: "姓名",
                data: 'name'
            }, {
                header: "性别",
                data: 'sex',
                filters: 'sexToCn'
            }, {
                header: '年龄',
                data: 'age'
            }, {
                header: '生日',
                data: 'birthDay',
                filters: 'date:\'yyyy-MM-dd\''
            }, {
                header: '地址',
                data: 'address'
            }, {
                header: '操作',
                template: '<a ng-click="grid.actions.edit(row)" ng-if="row.checked">编辑</a>'
            }];
        $scope.resourceInitCallback = function (api) {
            api.actions.edit = function (row) {
                api.getAllCheckedRows()
            }
        }

    });
});
